<?php
namespace Utils;
use config\rong_config;
require_once __DIR__."/../API/rongcloud.php";
require_once __DIR__ .'/../config/rong_config.php';
class RongUtils {
    private static $rong=null;
    public static function get($param) {
        if(self::$rong==null)
            self::$rong=new \RongCloud(rong_config::$appKey, rong_config::$appSecret);
        $result = self::$rong->user()->getToken($param["student_id"], $param["username"], 'http://www.rongcloud.cn/images/logo.png');
        $res= (array)json_decode($result);
        print_r($res);
        return $res["token"];
    }
    public static function pullall($param) {
        if(self::$rong==null)
            self::$rong=new \RongCloud(rong_config::$appKey, rong_config::$appSecret);
        $result = self::$rong->message()->broadcast('校级通知', 'RC:TxtMsg',"{\"content\":\"".$param."\",\"extra\":\"".$param."\"}");
		$aa=(array)json_decode($result);
		return $aa["code"];
    }
    public static function pullto($from,$to,$param) {
         if(self::$rong==null)
            self::$rong=new \RongCloud(rong_config::$appKey, rong_config::$appSecret);

         $result = self::$rong->message()->PublishSystem($from,$to, 'RC:TxtMsg',"{\"content\":\"".$param."\",\"extra\":\"helloExtra\"}", 'thisisapush', '{\"pushData\":\"hello\"}', '0', '0');
    $aa=(array)json_decode($result);
         return $aa["code"];
    }
}
